﻿using System;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.SharePoint.Common.ServiceLocation;

namespace VisualWebPart
{
    public class Presenter<IView, IModel>
    {
        public Presenter() 
        {
            IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent();
            Model = serviceLocator.GetInstance<IModel>();
        }

        public Presenter(SPSite site) 
        {
            if (site != null)
            {
                IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent(site);
                Model = serviceLocator.GetInstance<IModel>();
            }
        }

        protected IModel Model { get; set; }

        public IView View { get; set; }

        public virtual void OnViewInitialized() { }

        public virtual void OnViewLoaded() { }
    }
}
